package cn.kone.service.impl;

import cn.kone.pojo.domain.PayOrder;
import cn.kone.mapper.PayOrderMapper;
import cn.kone.service.IPayOrderService;
import cn.kone.util.WeChatUtil;
import cn.kone.utils.AssertUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuyu
 * @since 2024-04-07
 */
@Service
public class PayOrderServiceImpl extends ServiceImpl<PayOrderMapper, PayOrder> implements IPayOrderService {


    @Override
    public Object prePay(String orderNo) {
        PayOrder payOrder = getOne(new LambdaQueryWrapper<PayOrder>().eq(PayOrder::getOrderNo, orderNo));
        AssertUtil.isNotNull(payOrder,"没有查询到这个支付单~~~");

        return WeChatUtil.prepayWithRequestPayment(payOrder.getAmount().multiply(new BigDecimal("100")).intValue(),"",payOrder.getSubject(),payOrder.getPayOrderNo());
    }
}
